<?php

namespace app\admin\model\deerhome;

use think\Model;


class Worker extends Model
{

    

    

    // 表名
    protected $name = 'deerhome_worker';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'type_text'
    ];
    

    
    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2')];
    }

    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getUtelAttr($value, $data=[])
    {
        $value = $value ? $value : (isset($data['utel']) ? $data['utel'] : '');
        return \Tools\Config::tel($value);
    }

    public function shop()
    {
        return $this->belongsTo('Shop', 'jz_shop_id','id','s1','LEFT')->setEagerlyType(0);
    }
    public function lev()
    {
        return $this->belongsTo('WorkerLev', 'jz_worker_lev_id','id','l1','LEFT')->setEagerlyType(0);
    }
    public function card()
    {
        return $this->belongsTo('WorkerCard', 'id','jz_worker_id','c1','LEFT')->setEagerlyType(0);
    }

}
